<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 引入刚刚下载的 ECharts 文件 -->
    <script th:src="@{/echarts/echarts.min.js}"></script>
    <script th:src="@{/echarts/world.js}"></script>
    <script th:src="@{/echarts/china.js}"></script>
    <script th:src="@{/echarts/jquery-1.11.1.min.js}"></script>

    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <script th:src="@{/layui/layui.js}"></script>
</head>
<body  class="childrenBody">
    <div>
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
            <div id="main" style="width: 900px;height:700px;"></div>
        </div>
    </div>
    <script>
        //JS
        layui.use(['element', 'layer', 'util'], function(){
            var element = layui.element
                ,layer = layui.layer
                ,util = layui.util
                ,$ = layui.$;

            //头部事件
            util.event('lay-header-event', {
                //左侧菜单事件
                menuLeft: function(othis){
                    layer.msg('展开左侧菜单的操作', {icon: 0});
                }
                ,menuRight: function(){
                    layer.open({
                        type: 1
                        ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
                        ,area: ['260px', '100%']
                        ,offset: 'rt' //右上角
                        ,anim: 5
                        ,shadeClose: true
                    });
                }
            });

        });
    </script>


    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        var dataList = [];
        option = {
            title: {
                text: '新型冠状病毒肺炎疫情地图',
                subtext: '累计确诊人数（截止至北京时间2020-06-09 08:30）',
                left: 'center',
                top: 'top'
            },
            tooltip: {
                trigger: 'item',
                formatter: function(params) {
                    var value = params.value + '';
                    return params.seriesName + '<br/>' + params.name + ' : ' + value+'人';
                }
            },
            toolbox: {
                show: true,
                orient: 'vertical',
                left: 'right',
                top: 'center',
                feature: {
                    dataView: {
                        readOnly: false
                    },
                    restore: {},
                    saveAsImage: {}
                }
            },
            visualMap: {
                min: 0,
                max: 2200000,
                text: ['High', 'Low'],
                realtime: false,
                calculable: true,
                color: ['orangered', 'yellow', 'lightskyblue']
            }
        };

        $.ajax({
            url: "/queryGlobal",
            dataType: "json",
            success:function (data) {
                for (let i in data){
                    dataList[i] = data[i];
                }
                myChart.setOption({
                    series: [{
                        name: '新型冠状病毒肺炎疫情地图',
                        type: 'map',
                        mapType: 'world',
                        roam: true,
                        itemStyle: {
                            emphasis: {
                                label: {
                                    show: true
                                }
                            }
                        },
                        data: dataList
                    }]
                })
            }
        });

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>
</body>
</html>
